﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using ConnectionLayer;
using System.Windows.Forms;

namespace BusinessLayer
{
    public static class ClienteActions
    {
        public static bool CriarCliente(String NomeCli, String NIFCli, String MoradaCli, String Email, String telefone, String TipoCli)
        {
            ConnectionFactory con = new ConnectionFactory();

            try
            {
                con.GetConnection.Open();
                SqlCommand cmd = con.GetConnection.CreateCommand();
                cmd.CommandText = "insert into Cliente (nifCli, nomeCli, moradaCli, telefoneCli, emailCli, tipoCli, ActnAct) values(@NIFCli,@NomeCli,@MoradaCli,@telefone,@Email,@TipoCli,1)";
                cmd.Parameters.AddWithValue("@NIFCli", NIFCli);
                cmd.Parameters.AddWithValue("@NomeCli", NomeCli);
                cmd.Parameters.AddWithValue("@MoradaCli", MoradaCli);
                cmd.Parameters.AddWithValue("@telefone", telefone);
                cmd.Parameters.AddWithValue("@Email", Email);
                cmd.Parameters.AddWithValue("@TipoCli", TipoCli);
                int numRows = cmd.ExecuteNonQuery();
                return numRows > 0;
            }
            catch (Exception e) { MessageBox.Show(e.Message); return false; }
            finally
            {
                try
                {
                    con.GetConnection.Close();
                }
                catch (Exception e) { MessageBox.Show(e.Message); }
            }
        }
    }
}
